package com.group.transaction.config;

import com.group.transaction.model.ResultJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理配置类
 *
 * @author YunXing Pang
 * @date 2020/5/1
 */
@RestControllerAdvice
@Slf4j
public class ControllerAdviceConfig {

    /**
     * 捕获 异常，将异常映射为HTTP状态码500
     *
     * @param exception 异常
     * @return 数据返回
     */
    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResultJson exceptionHandler(Exception exception) {
        log.error("系统出现异常：{}", exception);
        return ResultJson.builder().code(0).message("系统打小差，请稍后再试！").build();
    }

}
